package cn.com.dhc.danlu.business.shopcar.holder;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.activity.delivery.order.viewholder.BaseViewHolder;
import cn.com.dhc.danlu.business.shopcar.bean.SellerBean;
import cn.com.dhc.danlu.business.shopcar.callback.ISellerClickCallback;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-02-27 17:04
 *
 * <p>
 * 内容描述区域
 * </p>
 */
public class SellerViewHolder extends BaseViewHolder<SellerBean> {
    private ImageView ivSelall;
    private ImageView ivCod;
    private ImageView ivVat;
    private TextView tvName;


    private ISellerClickCallback onStoreClick;

    public SellerViewHolder(View itemView, ISellerClickCallback callback) {
        super(itemView);

        this.onStoreClick = callback;

        initViews();
        setViews();
    }

    private void initViews() {
        ivCod = (ImageView) itemView.findViewById(R.id.iv_cod);
        ivVat = (ImageView) itemView.findViewById(R.id.iv_vat);
        ivSelall = (ImageView) itemView.findViewById(R.id.iv_selall);
        tvName = (TextView) itemView.findViewById(R.id.tv_name);
    }

    private void setViews() {
        ivSelall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                data.setSelected(!ivSelall.isSelected());
                onStoreClick.onStoreSel(getLayoutPosition() - 1, data.getMerchIndex(), data.getPromotionIndex(), !ivSelall.isSelected());
            }
        });
    }

    @Override
    protected void bindViewData(SellerBean data) {
        ivSelall.setSelected(data.isSelected());
        tvName.setText(data.getSellerName());
        ivCod.setVisibility(data.getSupportCod().equals("0") ? View.VISIBLE : View.GONE);
        ivVat.setVisibility(data.getSupportVatInvoice().equals("0") ? View.VISIBLE : View.GONE);
    }
}
